package cz.uhk.ppro.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import cz.uhk.ppro.form.SkladneniForm;

public class SkladneniValidator implements Validator{

	public boolean supports(Class<?> clazz) {
		return SkladneniForm.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		SkladneniForm sf = (SkladneniForm)target;
		if (sf.getCenaKc() <= 0) {
			errors.rejectValue("cenaKc", "cenaKc.required");
		}
		if (sf.getPocet() <= 0) {
			errors.rejectValue( "pocet", "skladnikPocet.required");
		}
	}

}
